package cll;

import org.apache.commons.math3.random.RandomDataImpl;
import static cll.Parameters.*;

public class Centrocyt extends Cell {

	private boolean saved = false;
	private boolean differentiated = false;
	
	public Centrocyt(Centroblast cb){
		type = Type.Centrocyt;
		environment = cb.environment;
		positionspeed = cb.positionspeed;
		antigen = cb.antigen;
		//CD38 = cb.CD38;
		 rayon = rayonCC;
	}
	public void changeDirection() {
		if(Math.random() < dt/duree_persistence_deplacement_CC){
			Place myplace = environment.getPlace(positionspeed);

			double anglePrivilegie = myplace.getDirection13();
			
			double randomDirection = (Math.random()-0.5)*2*Math.PI;
			
			double vx = alphaCC*Math.cos(anglePrivilegie) + Math.cos(randomDirection);
			double vy = alphaCC*Math.sin(anglePrivilegie) + Math.sin(randomDirection);
			
			double newDirection = Math.atan2(vy, vx);
			
			RandomDataImpl distribution = new RandomDataImpl();
			double valeur = distribution.nextPoisson(vitesse_CC);
			
			positionspeed.changeSpeed(newDirection,valeur );
		}	
	}

	public Cell transforme() {
		if (differentiated){
			type = Type.DeadCell;
			if(Math.random()< proba_recyclage){
				return new Centroblast(this);
			}
			else{
				return new OutputCell(this);
			}
			
		}
		return new DeadCell();
	}

	@Override
	public void apoptosis() {
		if((!saved)&(Math.random()< dt/taux_apoptose_CC)){
			type = Type.DeadCell;
		}
		
	}

	@Override
	public void dealWithChemokine() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void transition() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Cell Reproduction() {
		// TODO Auto-generated method stub
		return new DeadCell();
	}
	@Override
	public void interaction(Cell c) {
		//System.out.println(Type.TCell+" "+c.type);
		//System.out.println(c.type == Type.TCell);
		if (((!saved)&(c.type == Type.FollicularDendriticCell))&(Math.random()< Antigen.affinity(antigen,c.antigen))){
			saved = true;
		}
		if (((saved)&(c.type == Type.THelper))&(Math.random()< Antigen.affinity(antigen,c.antigen))){
			differentiated = true;
		}
		
		
	}
	
	

}
